(function() {
	function drawer() {
		this.canvasHeight = 300; // 画布高度
		this.areaHeight = 240; // 有效绘图 区域高度
		
	}
	
	drawer.prototype.init = function() {
		
	}
	
	// 绘制 线条
	drawer.prototype.line = function(canvasId, price, timeline, op) {
		op.interval = op.interval || 1;
		op.pix = this.getPixel(op.poor);
	
		var c = document.getElementById(canvasId);
		var ctx = c.getContext("2d");
		
		ctx.beginPath();
		ctx.lineWidth = 1;
		ctx.strokeStyle = op.color;
		ctx.lineJoin = "round";
		
		ctx.moveTo(this.getX(timeline[0], op.interval), this.getY(price[0], op));
		for(var i = 1, l = points.length; i < l; i++) {
			ctx.lineTo(this.getX(timeline[i], op.interval), this.getY(price[i], op));
		}
		ctx.stroke();
	}
	
	/**
	 * 根据时间戳 和 间隔， 获取X 坐标
	 */
	drawer.prototype.getX = function(timeline, interval) {
		return ( ((timeline / 10 + 8 * 360) % 8640) / interval ).toFixed(2);
	}
	
	/**
	 * 根据 点值，min，pix 获取Y坐标
	 */
	drawer.prototype.getY = function(p, op) {
		return this.areaHeight - (p - op.min) * op.pix;;
	}
	
	/**
	 * 获取像素比例， 1个刻度 对应多少像素
	 */
	drawer.prototype.getPixel = function(poor) {
		return (this.areaHeight / poor).toFixed(2);
	}
	
	/**
	 * 设置价格刻度
	 */
	function setGraduation(op) {
		var min =  /1000,
			max = LIB.arrayMax(arr)/1000,
			poor = (max - min) / 9;
				
		max = max - correctionValue;

		$(".graduation div").each(function() {
			max -= poor;
			$(this).html(max.toFixed(3));
		});
	}
	
	/**
	 * 清空画布
	 */
	drawer.prototype.clearCanvas = function(canvasId) {
		var c = document.getElementById(canvasId);
		var ctx=c.getContext("2d");
		ctx.clearRect(0, 0, c.width, c.height);
	}
	
	if(!window.DRAW) {
		window.DRAW = new drawer;
		DRAW.init();
	}
});